package com.zhudeshuai.zhudemolist.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;

import com.zhudeshuai.zhudemolist.R;
import com.zhudeshuai.zhudemolist.base.BaseActivity;
import com.zhudeshuai.zhudemolist.util.ToastUtil;

/**
 * ToolBar学习
 *
 * @author zhudeshuai
 * @since 16/4/11
 */
public class ToolBarDemoActivity extends BaseActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tool_bar_demo);
        initView();
    }

    private void initView() {
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        toolbar.setTitle("测试");
        toolbar.setLogo(R.mipmap.ic_launcher);
        toolbar.setSubtitle("subtitle测试");
        setSupportActionBar(toolbar);
        toolbar.setNavigationIcon(R.mipmap.ic_launcher);
        toolbar.setTitle("xiugai");
        toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.action_settings:
                        ToastUtil.showToast("设置");
                        break;
                    case R.id.action_settings2:
                        ToastUtil.showToast("设置2");
                        break;
                    case R.id.action_edit:
                        ToastUtil.showToast("编辑");
                        break;
                    case R.id.action_share:
                        ToastUtil.showToast("分享");
                        break;
                }
                return true;
            }
        });

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        return super.onOptionsItemSelected(item);
    }

    public static void open(Activity activity) {
        activity.startActivity(new Intent(activity, ToolBarDemoActivity.class));
    }
}
